package com.zmt.content.test;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zmt.xuechengplusbase.model.PageParams;
import com.zmt.xuechengplusbase.model.PageResult;
import com.zmt.content.dto.QueryCourseParamsDto;
import com.zmt.content.po.CourseBase;
import com.zmt.content.mapper.CourseBaseMapper;
import org.apache.commons.lang.StringUtils;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.List;


@SpringBootTest
public class test {

    @Autowired
    CourseBaseMapper courseBaseMapper;

    @Test
    public void testMapper(){
        CourseBase courseBase = courseBaseMapper.selectById(18);
        System.out.println(courseBase);
        LambdaQueryWrapper<CourseBase> wrapper = new LambdaQueryWrapper<>();
        QueryCourseParamsDto queryCourseParamsDto = new QueryCourseParamsDto();
        queryCourseParamsDto.setCourseName("java");
        //根据课程名称模糊查询
        wrapper.like(StringUtils.isNotEmpty(queryCourseParamsDto.getCourseName())
                ,CourseBase::getName
                ,queryCourseParamsDto.getCourseName());
        //根据审核状态查询
        wrapper.eq(StringUtils.isNotEmpty(queryCourseParamsDto.getAuditStatus())
                ,CourseBase::getAuditStatus
                ,queryCourseParamsDto.getAuditStatus());
        PageParams pageParams = new PageParams(1L,5L);

        Page<CourseBase> page = new Page<>(pageParams.getPageNo(), pageParams.getPageSize());


        Page<CourseBase> pageInfo = courseBaseMapper.selectPage(page, wrapper);

        //这是查询出来的数据
        List<CourseBase> records = pageInfo.getRecords();
        long count = pageInfo.getTotal();

        //因为要的是PageResult类型对象
        PageResult<CourseBase> pageResult = new PageResult(records,count,pageParams);
        System.out.println(pageResult);
    }
}
